<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Controller;

use AuctionCore\Account\Back\Employee;
use AuctionCore\AuctionOrder\AuOrderList as AuOrderList;
use AuctionCore\System\AuctionException;
use AuctionCore\Common\Page;

class HistoryDealController extends BaseController {

    public function __construct() {
        parent::__construct();
        //页面头部信息
        $head = C('HEAD_INDEX');
        $this->assign("web_title", $head['title']);
        $this->assign("web_keywords", $head['keywords']);
        $this->assign("web_description", $head['description']);
        $this->emp_id = $this->user_info['emp_id'];
        //模板赋值
        $this->assign("emp_id", $this->emp_id);
    }

    /**
     * 历史成交查询列表
     */
    public function index() {
        $this->display();
    }

    /**
     * 拍品查询列表数据
     */
    public function history_deal_list() {
        $page = I("get.p", 1);
        $size = 10;
        $params = array();
        $params['order_no'] = I('get.order_no');
        $params['brand_id'] = I("get.brand_id");
        $params['series_id'] = I("get.series_id");
        $params['model_id'] = I("get.model_id");
        $params['is_recommend'] = I('get.is_recommend');
        $params['start_time'] = I('get.start_time');
        $params['end_time'] = I('get.end_time');
        $params['emp_id'] = $this->emp_id;
        //获取list
        $cl = new AuOrderList();
        $result = $cl->get_history_deal_list($page, $size, $params);
        $list = empty($result['list']) ? array() : $result['list'];
        //分页
        $Page = new \AuctionCore\Common\AjaxPage($result['total'], $size, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %nextPage% %downPage%  %end% %jumpform%");
//        dump($list);
        $show = $Page->show();          // 分页显示输出
        $this->assign('page', $show);   // 赋值分页输出
        $this->assign('list', $list);
        $this->assign('p', $page);
        $this->assign('total', $result['total']);
        $this->display();
    }

    /**
     * 改变推荐、取消推荐拍单的状态
     */
    public function is_recommend_post() {
        try {
            $order_id = I('post.order_id/d');
            $is_recommend = I('post.is_recommend/d');
            $cl = new AuOrderList();
            $res = $cl->history_deal_post($order_id, $is_recommend);
            if ($res) {
                echo \AuctionCore\Common\Util::auto_jsonp_or_json($_REQUEST, array('code' => 200, 'msg' => ''));
            } else {
                echo \AuctionCore\Common\Util::auto_jsonp_or_json($_REQUEST, array('code' => 500, 'msg' => '操作失败'));
            }
        } catch (AuctionException $e) {
            echo \AuctionCore\Common\Util::auto_jsonp_or_json($_REQUEST, array('msg' => $e->getMessage(), 'code' => $e->getCode()));
            exit;
        }
    }

}
